package logic

import (
	"context"
	"rent/rentrpc/rentrpc"

	"rent/api/internal/svc"
	"rent/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NewPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNewPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewPasswordLogic {
	return &NewPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NewPasswordLogic) NewPassword(req *types.NewPasswordquest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	password, err := l.svcCtx.RentRpc.NewPassword(l.ctx, &rentrpc.NewPasswordRequest{
		Mobile:      req.Mobile,
		Password:    req.Password,
		NewPassword: req.NewPassword,
		SenSmsCode:  req.SenSmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "密码找回成功",
		Code:    200,
		Data:    password,
	}, nil
}
